<?php 
require_once('class.db.php');
class trangchu extends db {
	function config(){
		$qr = "SELECT * FROM `config`";
		return mysql_query($qr);
	}
	function seo($domain,$title,$description,$keywords,$image,$url){
		return '<base href="http://'.$domain.'/" />
<title>'.$title.'</title>
<meta name="title" content="'.$title.'" />
<meta name="description" content="'.$description.'" />
<meta name="keywords" content="'.$keywords.'" />
<meta name="robots" content="INDEX,FOLLOW" />
<meta http-equiv="content-language" content ="vi" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta property="og:title" content="'.$title.'" />
<meta property="og:description" content="'.$description.'" />
<meta property="og:image" content="'.$image.'" />
<meta property="og:url" content="'.$url.'" />
<link type="icon/x-icon" href="images/logo_icon.ico" rel="shortcut icon" />';
	}
	function home_about($id){
		$qr = "SELECT name,name_rewrite,summary,menu_id FROM info WHERE `delete`=0 AND status=1 AND `other`=1 AND id='{$id}'";
		return mysql_query($qr);
	}
	function home_product($idMenu){
		$qr = "SELECT name,name_rewrite,url_hinh,summary,description,menu_id FROM info WHERE `delete`=0 AND status=1 AND `other`=1 AND menu_id LIKE '%,{$idMenu},%' ORDER BY `date_update` DESC LIMIT ".max_product_home;
		return mysql_query($qr);
	}
	function home_info($idMenu){
		$qr = "SELECT name,name_rewrite,url_hinh,summary,description,menu_id FROM info WHERE `delete`=0 AND status=1 AND `other`=1 AND menu_id NOT LIKE '%,{$idMenu},%' ORDER BY `date_update` DESC LIMIT 10";
		return mysql_query($qr);
	}
	function slider_banner($id){
		$qr = "SELECT name,url_hinh,link FROM slider_banner WHERE `delete`=0 AND status=1 AND position_id='{$id}' ORDER BY date_update DESC";
		return mysql_query($qr);
	}
	function menu_one($alias){
		$qr = "SELECT id,name,name_rewrite,url,url_hinh,title,metaDescription,metaKeyword,type_id FROM menu WHERE `delete`=0 AND status=1 AND name_rewrite='{$alias}'";
		return mysql_query($qr);
	}
	function menu($level,$position){
		$qr = "SELECT id,name,url,title FROM menu WHERE `delete`=0 AND status=1 AND position_id LIKE '%,{$position},%' AND parent_id = {$level} ORDER BY `order`";
		return mysql_query($qr);
	}
	function getSubmenu($level,$position){
		$sql = $this->menu($level,$position);
		if(mysql_num_rows($sql) > 0){
			$view = '<ul>';
			while($row = mysql_fetch_array($sql)){
				$view .= '<li><a href="'.$row['url'].'" title="'.$row['name'].'">'.$row['name'].'</a>';
				$view .= $this->getSubmenu($row['id'],$position);
				$view .= '</li>';
			}
			mysql_free_result($sql);
			$view .= '</ul>';
		}
		return $view;
	}
	function navigator($url,$name,$title){
		return '<div id="navigator"><a href="/" title="Rượu Sim Phú Quốc">Trang chủ</a><a href="'.$url.'" title="'.$title.'">'.$name.'</a></div>';	
	}
	function detail($alias){
		$qr = "SELECT id,name,name_rewrite,url_hinh,description,content,date_create,metaKeyword FROM info WHERE `delete`=0 AND status=1 AND name_rewrite='{$alias}'";
		return mysql_query($qr);
	}
	function list_item($select,$table,$where,$limit=NULL){
		$qr = "SELECT {$select} FROM {$table} WHERE {$where} ORDER BY date_update DESC {$limit}";
		return mysql_query($qr);
	}
	function link_detail($menu_id){
		$str = explode(',',$menu_id);
		$i = count($str)-2;
		$qr = mysql_query("SELECT url FROM menu WHERE id='".$str[$i]."'");
		$row_m = mysql_fetch_array($qr);
		return $row_m['url'];
	}
	function phantrang($link,$page_number,$max_results,$select,$table,$where,$keyword=NULL,$catalog=NULL,$order=NULL){
		$qr = $this->list_item($select,$table,$where);
		$total = mysql_num_rows($qr);
		mysql_free_result($qr);
		
		$str = '<div style="clear:both"></div>';
		$total_pages = ceil($total / $max_results);
		if($total_pages > 1){
			if($page_number > 1){
				$prev = ($page_number - 1);
				$str .= "<a href='{$link}{$prev}/'>Previous</a>";
			}
			for($i = $page_number - 5; $i <= $page_number + 5 & $i <= $total_pages; $i++){
				if($page_number == $i){
					$str .= "<a href='{$link}{$i}/' style='color:#FFF; font-weight:bold; background-color:#FF75DD'>{$i}</a>";
				} elseif($i>0) {
					$str .= "<a href='{$link}{$i}/'>{$i}</a>";
				}
			}
			if($page_number < $total_pages){
				$next = ($page_number + 1);
				$str .= "<a href='{$link}{$next}/'>Next</a>";
			}
		}
		return $str;
	}
	function baivietkhac($idMenu,$idDetail){
		$qr = "SELECT name,name_rewrite FROM info WHERE `delete`=0 AND status=1 AND id<>'$idDetail' AND menu_id LIKE '%,{$idMenu},%' ORDER BY date_update DESC LIMIT 6";
		return mysql_query($qr);
	}
	function insert_nhanxet($name,$email,$content,$alias){
		$datetime = date('Y-m-d H:i:s');
		$qr = "INSERT INTO info_comment VALUES ('','{$datetime}','{$datetime}','{$content}','{$email}','{$name}','1','{$alias}','khachhang','','0')";
		return mysql_query($qr);
	}
	function view_nhanxet($alias){
		$qr = "SELECT name,content,date_create FROM info_comment WHERE `delete`=0 AND status=1 AND info_alias='{$alias}' ORDER BY date_update DESC";
		return mysql_query($qr);
	}
	function datetime($datetime){
		$m = explode(' ',$datetime);
		$date = explode('-',$m[0]);
		$time = explode(':',$m[1]);
		return "{$time[0]}:{$time[1]} ngày {$date[2]} tháng {$date[1]} năm {$date[0]}";
	}
	function order($hoten,$diachi,$dienthoai,$email,$soluong,$total,$yeucau){
		$date = date('Y-m-d H:i:s');
		$user_create = 'khachhang';
		mysql_query("INSERT INTO `order` VALUES ('','{$date}','{$date}','{$hoten}','{$diachi}','{$dienthoai}','{$email}','{$yeucau}','{$soluong}','{$total}','0','0','{$user_create}','')");
	}
}// end trangchu